package com.central.scheduler.api.controller;

import com.central.common.annotation.LoginUser;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.common.model.SysUser;
import com.central.scheduler.api.service.IProcessInstanceService;
import com.central.scheduler.api.service.ITaskDefinitionService;
import com.central.scheduler.api.service.ITaskInstanceService;
import com.central.scheduler.dao.model.ProcessInstance;
import com.central.scheduler.dao.model.TaskInstance;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author Tindy
 * @date 2021/6/24
 * @describe
 */
@RestController
@Api(tags = "taskInstance模块api")
@Slf4j
@RequestMapping("/taskInstance")
public class TaskInstanceController {

    @Autowired
    private ITaskInstanceService taskInstanceService;
    @ApiOperation(value = "查询taskInstance列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer",example = "1"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer",example = "10"),
            @ApiImplicitParam(name = "isTmp", value = "是否为临时", required = true, dataType = "Boolean",example = "false")
    })
    @GetMapping("/queryTaskInstances")
    public PageResult<TaskInstance> queryTaskInstances(@ApiIgnore @LoginUser SysUser user, @RequestParam Map<String, Object> params) {
        params.put("proId",user.getCurrentProjectId());
        return taskInstanceService.queryTaskInstances(params);
    }


    @ApiOperation(value = "根据作业流实例id查询taskInstance列表")
    @GetMapping("/findTaskInstances")
    public List<TaskInstance> findTaskInstances(@ApiIgnore @LoginUser SysUser user, Long processInstanceId) {
        return taskInstanceService.findTaskInstances(user.getCurrentProjectId(),processInstanceId);
    }

    @ApiOperation(value = "强制成功")
    @PostMapping(value = "/forceSuccess")
    public Result forceTaskSuccess(@ApiIgnore @LoginUser SysUser user, Long taskInstanceId){
        return taskInstanceService.forceTaskSuccess(user, taskInstanceId);
    }
}
